// (c) 2004 Wout de Zeeuw

using System;
using System.ComponentModel;

namespace CaveArt.UIcomp
{
	/// <summary>
	/// Enhances the <see cref="PropertyDescriptor"/>.
	/// </summary>
	/// <remarks>
	/// All values are gotten from the <see cref="PropertyAttributes"/> 
	/// object passed to the constructor.
	/// </remarks>
	public class PropertyDescriptorEx : PropertyDescriptor
	{
		private PropertyDescriptor			baseDescriptor; 
		private PropertyAttributes			propAttributes;

		#if DYNAMIC_PROPERTY_TEST
		private PropertyCommandCollection	propCommands;

		[Category ("Property Control")]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		// [Editor(typeof(CustomCommandsCollectionEditor),typeof(System.Drawing.Design.UITypeEditor))]
		public PropertyCommandCollection PropertyCommands
		{
			get
			{
				if (propCommands==null)
				{
					propCommands= new PropertyCommandCollection();	
				}

				return propCommands;
			}
		}
		#endif

		/// <summary>
		/// Constructor.
		/// </summary>
		public PropertyDescriptorEx(
			PropertyDescriptor baseDescriptor,
			PropertyAttributes Attributes
		) : base(baseDescriptor)
		{
			this.baseDescriptor = baseDescriptor;
			this.propAttributes = Attributes;
		}

		public override bool CanResetValue(object component)
		{
			return baseDescriptor.CanResetValue(component);
		}

		public override Type ComponentType
		{
			get { return baseDescriptor.ComponentType; }
		}

		public override string DisplayName
		{
			get 
			{
				return propAttributes.DisplayName;
			}
		}

		public override string Description
		{
			get
			{
				return propAttributes.Description;
			}
		}

		public override string Category
		{
			get
			{
				return propAttributes.Category;
			}
		}

		public override object GetValue(object component)
		{
			return this.baseDescriptor.GetValue(component);
		}

		public override bool IsReadOnly
		{
			get {
				return propAttributes.IsReadOnly;
			}
		}

		public override bool IsBrowsable
		{
			get {
				return propAttributes.IsBrowsable;
			}
		}

		public override string Name
		{
			get { return this.baseDescriptor.Name; }
		}

		public override Type PropertyType
		{
			get { return this.baseDescriptor.PropertyType; }
		}

		public override void ResetValue(object component)
		{
			this.baseDescriptor.ResetValue(component);
		}

		public override bool ShouldSerializeValue(object component)
		{
			return this.baseDescriptor.ShouldSerializeValue(component);
		}

		public override void SetValue(object component, object value)
		{
			this.baseDescriptor.SetValue(component, value);
		}
	}
}
